/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

using ll = long long;

constexpr int maxn = 100;

bool lnk[maxn + 1][maxn + 1];
int a[maxn + 1][maxn + 1], dif[(maxn + 1) * (maxn + 1)];
bool state[maxn + 1];
char ans[(maxn + 1) * (maxn + 1)][maxn + 1];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    a[u][v] = a[v][u] = w;
    lnk[u][v] = lnk[v][u] = true;
  }
  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    state[i] = true;
  }
  std::vector<int> v;
  std::set<int> tmp;
  v.push_back(n);
  ll tim = 0;
  while (true) {
    if (cnt == n * n || state[1] == false) {
      break;
    }
    int diff = 0x7fffffff;
    for (auto i : v) {
      for (int j = 1; j <= n; ++j) {
        if (lnk[i][j] && state[j]) {
          diff = std::min(diff, a[i][j]);
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      ans[cnt + 1][i] = (state[i] ? '1' : '0');
    }
    for (auto i : v) {
      for (int j = 1; j <= n; ++j) {
        if (lnk[i][j] && state[j]) {
          a[i][j] -= diff, a[j][i] -= diff;
          if (a[i][j] == 0) {
            state[j] = false;
            tmp.insert(j);
          }
        }
      }
    }
    for (auto i : tmp) {
      v.push_back(i);
    }
    tmp.clear();
    tim += diff;
    dif[cnt + 1] = diff;
    ++cnt;
  }
  if (cnt == n * n) {
    cout << "inf\n";
  } else {
    cout << tim << ' ' << cnt << '\n';
    for (int i = 1; i <= cnt; ++i) {
      for (int j = 1; j <= n; ++j) {
        cout << ans[i][j];
      }
      cout << ' ' << dif[i] << '\n';
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("D. Tenzing and His Animal Friends.in", "r", stdin);
  freopen("D. Tenzing and His Animal Friends.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
